{include file="public/header" /}
<link rel="stylesheet" href="/static/admin/css/base.css" media="all">
<style>
    html {
        background-color: #f2f2f2 !important;
    }
    .m-table {
        background-color: rgb(255, 255, 255);
        /*margin-top: 5px;*/
        display: none;
        z-index: 1005;
        position: absolute;
        width: 100%;
        /*max-width: 80%;*/
        box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
    }

    #mTable_choose {
        margin: 0 !important;
    }

    .layui-table table tr:hover, .layui-table-hover {
        background-color: #FFF9E6 !important;
    }
</style>
<body>
<div class="layui-fluid layui-anim-fadein">
    <div class="layui-card layui-col-xs12 layui-col-sm12 layui-col-md12">
        <div style="height: 10px"></div>
        <div class="layui-card-body" style="padding-right: 2% !important;">
            <form class="layui-form" action="{:url('save')}" id="form">
                <input type="hidden" name="id" value="{$id}"/>

                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-inline">
                        <select id="type" name="type" lay-verify="required" lay-filter="type" lay-reqtext="请选择类型" lay-verType="tips">
                            <option value="">请选择</option>
                            {foreach name="type" item="vo"}
                            <option value="{$vo.id}" {if isset($info) && $info.type==$vo.id}selected{/if}>{$vo.title}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item account" {if $info.type>6}style="display: none;"{/if}>
                    <label class="layui-form-label">金额</label>
                    <div class="layui-input-inline">
                        <input type="text" name="amount" value="{$info.amount}" autocomplete="off" class="layui-input">
                    </div>
                    <label class="layui-form-label">中奖几率</label>
                    <div class="layui-input-inline">
                        <input type="number" name="odds" value="{$info.odds*100}" autocomplete="off" class="layui-input">
                    </div>
                    <span class="layui-word-aux">%</span>
                </div>

                <div class="layui-form-item product" {if $info.type !=7 }style="display: none;"{/if}>
                    <label class="layui-form-label">商品</label>
                    <div class="layui-input-inline">
                        <select id="product_id" name="product_id" lay-filter="product_id" lay-reqtext="请选择商品" lay-verType="tips">
                            <option value="">请选择商品</option>
                            {foreach name="$product" item="vo"}
                            <option value="{$vo.id}" {if isset($info) && $info.product_id==$vo.id}selected{/if}>{$vo.title}</option>
                            {/foreach}
                        </select>
                    </div>

                    <label class="layui-form-label">中奖次数</label>
                    <div class="layui-input-inline">
                        <input type="number" name="count" value="{$info.count}" autocomplete="off" class="layui-input">
                    </div>
                    <span class="layui-word-aux">次</span>
                </div>

                <div class="layui-form-item uploadImageBox">
                    <label class="layui-form-label">图标</label>

                    <div class="layui-input-block">
                        <div class="layui-tab-item layui-show" style="width: 260px;">
                            <div class="layui-upload-drag uploadImage">
                                <i class="layui-icon"></i>
                                <p>点击上传，或将文件拖拽到此处</p>
                                <div>
                                    <hr>
                                    <img src="{$info?$info.image:''}"  class="layui-upload-img showImage" alt="上传成功后渲染" style="max-width: 50%">
                                    <input type="hidden" name="image" value="{$info?$info.image:''}" class="inpImage"  lay-verify="required" lay-reqtext="请上传图标" />
                                </div>
                            </div><input class="layui-upload-file" type="file" accept="" name="file">
                        </div>

                    </div>
                </div>
                <div class="layui-form-item" style="text-align: center">
                    <div class="layui-input-block">
                        <button class="layui-btn recharge" lay-filter="save" lay-submit formObj="#form">确定
                        </button>
                    </div>
                </div>

            </form>
        </div>

    </div>
</div>
</body>
{include file="public/footer" /}
<script>
    layui.use(['form', 'table'], function () {
        table = layui.table;
        mTable_wrap_choose = $('#mTable_wrap_choose');
        form = layui.form;

        form.on('select(type)', function (data) {
            if (data.value <= 5) {
                $('.account').show();
                $('.product').hide();
            } else {
                $('.product').show();
                $('.account').hide();
            }
        });


        //监听表单提交
        form.on('submit(save)', function (data) {
            layer.load();
            var btn = $(this);
            btn.attr('disabled', true);
            formObj = $($(this).attr('formObj'));
            url = formObj.attr('action');
            $.ajax({
                type: 'POST',
                url: url,
                data: formObj.serialize(),
                dataType: "json",
                success: function (data) {
                    layer.closeAll();
                    if (data.code == 1) {
                        notify.success(data.msg, 1500, function () {
                            let index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.window.location.reload();
                        });
                    } else {
                        notify.error(data.msg);
                        btn.removeAttr('disabled');
                    }
                },
                error(e) {
                    layer.closeAll();
                    btn.removeAttr('disabled');
                }
            });
            return false;
        })



    });
</script>
</html>